<?php

include_once 'SGBD/Postgre.php';
include_once 'SGBD/Oracle.php';
include_once 'SGBD/MySQL.php';

class ModelCreator_Database_Connection {

    protected $_host;
    protected $_port;
    protected $_user;
    protected $_password;
    protected $_database;
    protected $_selectedTables;
    public $_schema;
    public $objConn;

    public function __construct($arrPostConnection, $arrPostTables = NULL) {
        $this->_host = $arrPostConnection[host];
        $this->_port = $arrPostConnection[port];
        $this->_user = $arrPostConnection[user];
        $this->_password = $arrPostConnection[password];
        $this->_database = $arrPostConnection[database];
        $this->_schema = $arrPostConnection[schema];
        $this->_selectedTables = $arrPostTables;
        $this->identifyDatabase($arrPostConnection[opt_sgbd]);
    }

    private function identifyDatabase($sgbd) {
      
        switch ($sgbd) {
            case 'oracle':
                $this->objConn = new ModelCreator_Database_SGBD_Oracle($this->_host, $this->_port, $this->_database,
                                $this->_user, $this->_password, $this->_schema, $this->_selectedTables);
                break;
            case 'postgre':
                $this->objConn = new ModelCreator_Database_SGBD_Postgre($this->_host, $this->_port, $this->_database,
                                $this->_user, $this->_password, $this->_schema, $this->_selectedTables);
                return $this->objConn;
                break;
            
             case 'mysql':
                $this->objConn = new ModelCreator_Database_SGBD_MySQL($this->_host, $this->_port, $this->_database,
                                $this->_user, $this->_password, $this->_selectedTables);
                return $this->objConn;
                break;

            default:
                break;
        }
    }

}
